<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<title>订单</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../uploadjs/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.fileupload.js"></script>
<script type="text/javascript" src="../js/auth.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:100px;background:#B3DFDA;padding:10px">
<div style="float:right;clear:both;margin-top:15px;margin-right:20px">
    <a href="javascript:logout()">注销</a>
    </div>
    <h2>蛋糕商城</h2>
    <h3>从2025为公众服务</h3>
</div>
<div data-options="region:'west',split:true,title:'主菜单'" style="width:180px;padding:0px;">
<div onclick="window.location='../pages/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">主页</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../admin/index'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">蛋糕商城后台</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/goodses.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">货品</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/custorders.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/orderitems.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单项</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/recommends.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">推荐</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/types.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">类型</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/roles.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">角色</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/permissions.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/users.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/profile.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户资料</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkcustorderorderitem.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接订单订单项</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkrolepermission.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接角色许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkuserrole.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接用户角色</div><div class="menu-icon icon-add"></div></div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'属性'" style="width:250px;overflow: hidden">
</div>
<div data-options="region:'south',border:false" style="height:40px;background:#A9FACD;padding:10px;text-align: center">
    蛋糕商城
</div>
<div data-options="region:'center',title:'第三代动词算子式代码生成器：光　生成结果'">
<div title="搜索面板" class="easyui-panel" style="width:1600px;height:200px">
<form id="ffsearch" method="post">
<table cellpadding="5">
<tr>
<td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td>
<td>活跃:</td><td><input  class='easyui-textbox' type='text' name='active' id='active' value='' data-options="required:false"/></td>
<td>总价:</td><td><input  class='easyui-textbox' type='text' name='total' id='total' value='' data-options="required:false"/></td>
<td>
        <select id="actionSelect" class='easyui-select' style="	width:90px;height:28px" onchange="toggleBtnShow(this.value)">
            <option value="1" selected>搜索</option>
            <option value="2">Excel过滤</option>
            <option value="3">PDF过滤</option>
            <option value="4">Word过滤</option>
            <option value="5">PPT过滤</option>
        </select>
        </td><td>
        <div id="button-bar">
            <a href="#" class="easyui-linkbutton" style="display:block;width:110px;height:28px" data-options="iconCls:'icon-search'" onclick="searchCustOrdersByFieldsByPage()">搜索</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterCustOrdersExcel()">Excel过滤</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterCustOrdersPDF()"">PDF过滤</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterCustOrdersWord()"">Word过滤</a>
            <a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterPPTCustOrders()"">PPT过滤</a>
        </div>
        </td><td>
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width:80px" data-options="iconCls:'icon-clear'"  onclick="clearForm('ffsearch');toggleBtnShow(1);$('#actionSelect').val(1)">清除</a>
</td>
</tr>
<tr>
<td>商品总数:</td><td><input  class='easyui-textbox' type='text' name='amount' id='amount' value='' data-options="required:false"/></td>
<td>状态:</td><td><input  class='easyui-textbox' type='text' name='status' id='status' value='' data-options="required:false"/></td>
<td>支付方式:</td><td><input  class='easyui-textbox' type='text' name='paytype' id='paytype' value='' data-options="required:false"/></td>
<td></td><td colspan='3'></td>
</tr>
<tr>
<td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td>
<td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td>
<td>日期时间:</td><td><input  class='easyui-datetimebox' type='text' name='orderDateTime' id='orderDateTime' value='' data-options="required:false,parser:parseDateTime,formatter:formatDateTime"/></td>
<td></td><td colspan='3'></td>
</tr>
<tr>
<td>用户:</td><td><input  class='easyui-combobox' type='text' name='user' id='user' value='' data-options="required:false,valueField:'id',textField:'userName',method:'post',url:'../userController/listActiveUsers',loadFilter:function(data){return data.rows}"/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td></td><td colspan='3'></td>
</tr>
</table>
</form>
</div>
<table id="dg" class="easyui-datagrid" title="订单清单" style="width:1600px;height:600px" data-options="singleSelect:false,url:'../custOrderController/searchCustOrdersByFieldsByPage',queryParams:params,method:'post',pagination:true,toolbar:toolbar">
<thead>
<tr>
<th data-options="field:'id',checkbox:true">序号</th>
<th data-options="field:'name',width:80">名字</th>
<th data-options="field:'active',width:80">活跃</th>
<th data-options="field:'total',width:80">总价</th>
<th data-options="field:'amount',width:80">商品总数</th>
<th data-options="field:'status',width:80">状态</th>
<th data-options="field:'paytype',width:80">支付方式</th>
<th data-options="field:'phone',width:80">电话</th>
<th data-options="field:'address',width:80">地址</th>
<th data-options="field:'orderDateTime',width:80">日期时间</th>
<th data-options="field:'user',width:80,formatter:translateUser">用户</th>
</tr>
</thead>
</table>
<div class="easyui-window" title="新增订单" id="waddCustOrder" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td></tr>
<tr><td>总价:</td><td><input  class='easyui-textbox' type='text' name='total' id='total' value='' data-options="required:false"/></td></tr>
<tr><td>商品总数:</td><td><input  class='easyui-textbox' type='text' name='amount' id='amount' value='' data-options="required:false"/></td></tr>
<tr><td>状态:</td><td><input  class='easyui-textbox' type='text' name='status' id='status' value='' data-options="required:false"/></td></tr>
<tr><td>支付方式:</td><td><input  class='easyui-textbox' type='text' name='paytype' id='paytype' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>日期时间:</td><td><input  class='easyui-datetimebox' type='text' name='orderDateTime' id='orderDateTime' value='' data-options="required:false,parser:parseDateTime,formatter:formatDateTime"/></td></tr>
<tr><td>用户:</td><td><input  class='easyui-combobox' type='text' name='user' id='user' value='' data-options="required:false,valueField:'id',textField:'userName',method:'post',url:'../userController/listActiveUsers',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addCustOrder()">新增</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm('ff')">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#waddCustOrder').window('close')">取消</a>
</div>
</div>
<div class="easyui-window" title="编辑订单" id="wupdateCustOrder" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ffedit" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td></tr>
<tr><td>总价:</td><td><input  class='easyui-textbox' type='text' name='total' id='total' value='' data-options="required:false"/></td></tr>
<tr><td>商品总数:</td><td><input  class='easyui-textbox' type='text' name='amount' id='amount' value='' data-options="required:false"/></td></tr>
<tr><td>状态:</td><td><input  class='easyui-textbox' type='text' name='status' id='status' value='' data-options="required:false"/></td></tr>
<tr><td>支付方式:</td><td><input  class='easyui-textbox' type='text' name='paytype' id='paytype' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>日期时间:</td><td><input  class='easyui-datetimebox' type='text' name='orderDateTime' id='orderDateTime' value='' data-options="required:false,parser:parseDateTime,formatter:formatDateTime"/></td></tr>
<tr><td>用户:</td><td><input  class='easyui-combobox' type='text' name='user' id='user' value='' data-options="required:false,valueField:'id',textField:'userName',method:'post',url:'../userController/listActiveUsers',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateCustOrder()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ffedit').form('clear');">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wupdateCustOrder').window('close')">取消</a>
</div>
</div>
<div class="easyui-window" title="查看订单" id="wviewCustOrder" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ffview" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='name' id='name' value='' data-options="required:false"/></td></tr>
<tr><td>总价:</td><td><input  class='easyui-textbox' type='text' name='total' id='total' value='' data-options="required:false"/></td></tr>
<tr><td>商品总数:</td><td><input  class='easyui-textbox' type='text' name='amount' id='amount' value='' data-options="required:false"/></td></tr>
<tr><td>状态:</td><td><input  class='easyui-textbox' type='text' name='status' id='status' value='' data-options="required:false"/></td></tr>
<tr><td>支付方式:</td><td><input  class='easyui-textbox' type='text' name='paytype' id='paytype' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>日期时间:</td><td><input  class='easyui-datetimebox' type='text' name='orderDateTime' id='orderDateTime' value='' data-options="required:false,parser:parseDateTime,formatter:formatDateTime"/></td></tr>
<tr><td>用户:</td><td><input  class='easyui-combobox' type='text' name='user' id='user' value='' data-options="required:false,valueField:'id',textField:'userName',method:'post',url:'../userController/listActiveUsers',loadFilter:function(data){return data.rows}"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wviewCustOrder').window('close')">关闭</a>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var params = {};
var pagesize = 10;
var pagenum = 1;
var toolbar = [
{
    text:'查看',
    iconCls:'icon-search',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        $("#ffview").find("#id").val(rows[0]["id"]);
        $("#ffview").find("#name").textbox("setValue",rows[0]["name"]);
        $("#ffview").find("#total").textbox("setValue",rows[0]["total"]);
        $("#ffview").find("#amount").textbox("setValue",rows[0]["amount"]);
        $("#ffview").find("#status").textbox("setValue",rows[0]["status"]);
        $("#ffview").find("#paytype").textbox("setValue",rows[0]["paytype"]);
        $("#ffview").find("#phone").textbox("setValue",rows[0]["phone"]);
        $("#ffview").find("#address").textbox("setValue",rows[0]["address"]);
        $("#ffview").find("#orderDateTime").textbox("setValue",rows[0]["orderDateTime"]);
        $("#ffview").find("#user").combobox("setValue",rows[0]["user"]);
        var checkboxs = $("#ffview").find("input[name='active']");
        for (var i=0;i<checkboxs.length;i++){
            if (checkboxs.get(i).value == ""+rows[0]["active"]) checkboxs.get(i).checked=true;
        }
        $('#wviewCustOrder').window('open');
    }
}
,
{
    text:'新增',
    iconCls:'icon-add',
    handler:function(){
        $('#waddCustOrder').window('open');
    }
}
,
{
    text:'编辑',
    iconCls:'icon-edit',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        $("#ffedit").find("#id").val(rows[0]["id"]);
        $("#ffedit").find("#name").textbox("setValue",rows[0]["name"]);
        $("#ffedit").find("#total").textbox("setValue",rows[0]["total"]);
        $("#ffedit").find("#amount").textbox("setValue",rows[0]["amount"]);
        $("#ffedit").find("#status").textbox("setValue",rows[0]["status"]);
        $("#ffedit").find("#paytype").textbox("setValue",rows[0]["paytype"]);
        $("#ffedit").find("#phone").textbox("setValue",rows[0]["phone"]);
        $("#ffedit").find("#address").textbox("setValue",rows[0]["address"]);
        $("#ffedit").find("#orderDateTime").textbox("setValue",rows[0]["orderDateTime"]);
        $("#ffedit").find("#user").combobox("setValue",rows[0]["user"]);
        var checkboxs = $("#ffedit").find("input[name='active']");
        for (var i=0;i<checkboxs.length;i++){
            if (checkboxs.get(i).value == ""+rows[0]["active"]) checkboxs.get(i).checked=true;
        }
        $('#wupdateCustOrder').window('open');
    }
}
,
{
    text:'软删除',
    iconCls:'icon-remove',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        softDeleteCustOrder(id);
    }
}
,
{
    text:'激活',
    iconCls:'icon-tip',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        activateCustOrder(id);
    }
}
,
{
    text:'克隆',
    iconCls:'icon-add',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        cloneCustOrder(id);
    }
}
,
{
    text:'删除',
    iconCls:'icon-remove',
    handler:function(){
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if ($.messager.confirm("警告","确认要删除选定记录吗？", function(data){
            if (data){
                if (rows.length > 1) {
                    $.messager.alert("警告","请选定一条记录！","warning");
                    return;
                }
                var id = rows[0]["id"];
                deleteCustOrder(id);
            }
        }));
}
}
,
{
    text:'切换',
    iconCls:'icon-cut',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        toggleCustOrder(id);
    }
}
,
{
    text:'留一切换',
    iconCls:'icon-cut',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        if (rows.length > 1) {
            $.messager.alert("警告","请选定一条记录！","warning");
            return;
        }
        var id = rows[0]["id"];
        toggleOneCustOrder(id);
    }
}
,'-',
{
    text:'批软删除',
    iconCls:'icon-remove',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        var ids = "";
        for(var i=0;i<rows.length;i++){
            ids += rows[i]["id"];
            if (i < rows.length-1) ids += ",";
        }
        softDeleteAllCustOrders(ids);
    }
}
,
{
    text:'批激活',
    iconCls:'icon-tip',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        var ids = "";
        for(var i=0;i<rows.length;i++){
            ids += rows[i]["id"];
            if (i < rows.length-1) ids += ",";
        }
        activateAllCustOrders(ids);
    }
}
,
{
    text:'批克隆',
    iconCls:'icon-add',
    handler:function(){ 
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        var ids = "";
        for(var i=0;i<rows.length;i++){
            ids += rows[i]["id"];
            if (i < rows.length-1) ids += ",";
        }
        cloneAllCustOrders(ids);
    }
}
,
{
    text:'批删除',
    iconCls:'icon-remove',
    handler:function(){
        var rows = $("#dg").datagrid("getChecked");
        if (rows == undefined || rows == null || rows.length == 0 ){
            $.messager.alert("警告","请选定记录！","warning");
            return;
        }
        if ($.messager.confirm("警告","确认要删除选定记录吗？",function(data){
            if (data){
                var ids = "";
                for(var i=0;i<rows.length;i++){
                    ids += rows[i]["id"];
                    if (i < rows.length-1) ids += ",";
                }
                deleteAllCustOrders(ids);
            }
        }));
    }
}
,
{
    text:'Excel导出',
    iconCls:'icon-sum',
    handler:function(){
        window.location.href="../custOrderController/exportCustOrders";
    }
}
,
{
    text:'PDF导出',
    iconCls:'icon-print',
    handler:function(){
        window.location.href="../custOrderController/exportCustOrdersPDF";
    }
}
,
{
    text:'Word导出',
    iconCls:'icon-save',
    handler:function(){
        window.location.href="../custOrderController/exportCustOrdersWord";
    }
}
,
{
    text:'PPT导出',
    iconCls:'icon-tip',
    handler:function(){
        window.location.href="../custOrderController/exportPPTCustOrders";
    }
}
];
$(document).ready(function(){
    checkAccessCustOrder();
    $("#dg").datagrid("load");
});
function clearForm(formId){
$('#'+formId).form('clear');
}
function addCustOrder(){
    if ($("#ff").form("validate")) {
        $.ajax({
            type: "post",
            url: "../custOrderController/addCustOrder",
            data: JSON.stringify({
                name:$("#ff").find("#name").val(),
                active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
                total:$("#ff").find("#total").val(),
                amount:$("#ff").find("#amount").val(),
                status:$("#ff").find("#status").val(),
                paytype:$("#ff").find("#paytype").val(),
                phone:$("#ff").find("#phone").val(),
                address:$("#ff").find("#address").val(),
                orderDateTime:$("#ff").find("#orderDateTime").datetimebox("getValue"),
                user:$("#ff").find("#user").combobox("getValue"),
            }),
            dataType: 'json',
            contentType:"application/json;charset=UTF-8",
            success: function(data, textStatus) {
                if (data.success) {
                    window.location.reload();
                }
                },
            complete : function(XMLHttpRequest, textStatus) {
            },
            error : function(XMLHttpRequest,textStatus,errorThrown) {
                alert("Error:"+textStatus);
                alert(errorThrown.toString());
            }
        });
    }
}

function updateCustOrder(){
    $.ajax({
        type: "post",
        url: "../custOrderController/updateCustOrder",
        data: JSON.stringify({
            id:$("#ffedit").find("#id").val(),
            name:$("#ffedit").find("#name").val(),
            active:parseBoolean($("#ffedit").find("input[name='active']:checked").val()),
            total:$("#ffedit").find("#total").val(),
            amount:$("#ffedit").find("#amount").val(),
            status:$("#ffedit").find("#status").val(),
            paytype:$("#ffedit").find("#paytype").val(),
            phone:$("#ffedit").find("#phone").val(),
            address:$("#ffedit").find("#address").val(),
            orderDateTime:$("#ffedit").find("#orderDateTime").datetimebox("getValue"),
            user:$("#ffedit").find("#user").combobox("getValue"),
        }),
        dataType: 'json',
        contentType:"application/json;charset=UTF-8",
        success: function(data, textStatus) {
            if (data.success){
                $("#wupdateCustOrder").window('close');
                $("#dg").datagrid("load");
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    }); 
}

function softDeleteCustOrder(id){
    $.ajax({
        type: "post",
        url: "../custOrderController/softDeleteCustOrder",
        data: {
            "id":id	
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function activateCustOrder(id){
    $.ajax({
        type: "post",
        url: "../custOrderController/activateCustOrder",
        data: {
            "id":id
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function cloneCustOrder(id){
    $.ajax({
        type: "post",
        url: "../custOrderController/cloneCustOrder",
        data: {
            "id":id	
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function deleteCustOrder(id){
    $.ajax({
        type: "post",
        url: "../custOrderController/deleteCustOrder",
        dataType: 'json',
        data:{"id":id},
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    }); 
}

function toggleCustOrder(id){
    $.ajax({
        type: "post",
        url: "../custOrderController/toggleCustOrder",
        data: {
            "id":id
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function toggleOneCustOrder(id){
    $.ajax({
        type: "post",
        url: "../custOrderController/toggleOneCustOrder",
        data: {
            "id":id
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function softDeleteAllCustOrders(ids){
    $.ajax({
        type: "post",
            url: "../custOrderController/softDeleteAllCustOrders",
            data: {
                ids:ids
            },
            dataType: 'json',
            success: function(data, textStatus) {
                $("#dg").datagrid("load");
            },
            complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function activateAllCustOrders(ids){
    $.ajax({
        type: "post",
            url: "../custOrderController/activateAllCustOrders",
            data: {
                ids:ids
            },
            dataType: 'json',
            success: function(data, textStatus) {
                $("#dg").datagrid("load");
            },
            complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function cloneAllCustOrders(ids){
    $.ajax({
        type: "post",
            url: "../custOrderController/cloneAllCustOrders",
            data: {
                ids:ids
            },
            dataType: 'json',
            success: function(data, textStatus) {
                $("#dg").datagrid("load");
            },
            complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function deleteAllCustOrders(ids){
    $.ajax({
        type: "post",
        url: "../custOrderController/deleteAllCustOrders",
        data: {
            ids:ids
        },
        dataType: 'json',
        success: function(data, textStatus) {
            $("#dg").datagrid("load");
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
}

function searchCustOrdersByFieldsByPage(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        total:$("#ffsearch").find("#total").val(),
        amount:$("#ffsearch").find("#amount").val(),
        status:$("#ffsearch").find("#status").val(),
        paytype:$("#ffsearch").find("#paytype").val(),
        phone:$("#ffsearch").find("#phone").val(),
        address:$("#ffsearch").find("#address").val(),
        orderDateTime:$("#ffsearch").find("#orderDateTime").datetimebox("getValue"),
        user:$("#ffsearch").find("#user").combobox("getValue"),
    };
    $("#dg").datagrid({queryParams:params});
}

function filterCustOrdersExcel(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        total:$("#ffsearch").find("#total").val(),
        amount:$("#ffsearch").find("#amount").val(),
        status:$("#ffsearch").find("#status").val(),
        paytype:$("#ffsearch").find("#paytype").val(),
        phone:$("#ffsearch").find("#phone").val(),
        address:$("#ffsearch").find("#address").val(),
        orderDateTime:$("#ffsearch").find("#orderDateTime").datetimebox("getValue"),
        user:$("#ffsearch").find("#user").combobox("getValue"),
    };
    var params0 = $.param(params);
    document.location.href = "../custOrderController/filterCustOrdersExcel?" + params0;
}

function filterCustOrdersPDF(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        total:$("#ffsearch").find("#total").val(),
        amount:$("#ffsearch").find("#amount").val(),
        status:$("#ffsearch").find("#status").val(),
        paytype:$("#ffsearch").find("#paytype").val(),
        phone:$("#ffsearch").find("#phone").val(),
        address:$("#ffsearch").find("#address").val(),
        orderDateTime:$("#ffsearch").find("#orderDateTime").datetimebox("getValue"),
        user:$("#ffsearch").find("#user").combobox("getValue"),
    };
    var params0 = $.param(params);
    document.location.href = "../custOrderController/filterCustOrdersPDF?" + params0;
}

function filterCustOrdersWord(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        total:$("#ffsearch").find("#total").val(),
        amount:$("#ffsearch").find("#amount").val(),
        status:$("#ffsearch").find("#status").val(),
        paytype:$("#ffsearch").find("#paytype").val(),
        phone:$("#ffsearch").find("#phone").val(),
        address:$("#ffsearch").find("#address").val(),
        orderDateTime:$("#ffsearch").find("#orderDateTime").datetimebox("getValue"),
        user:$("#ffsearch").find("#user").combobox("getValue"),
    };
    var params0 = $.param(params);
    document.location.href = "../custOrderController/filterCustOrdersWord?" + params0;
}

function filterPPTCustOrders(){
    params = {
        name:$("#ffsearch").find("#name").val(),
        active:parseBoolean($("#ffsearch").find("#active").val()),
        total:$("#ffsearch").find("#total").val(),
        amount:$("#ffsearch").find("#amount").val(),
        status:$("#ffsearch").find("#status").val(),
        paytype:$("#ffsearch").find("#paytype").val(),
        phone:$("#ffsearch").find("#phone").val(),
        address:$("#ffsearch").find("#address").val(),
        orderDateTime:$("#ffsearch").find("#orderDateTime").datetimebox("getValue"),
        user:$("#ffsearch").find("#user").combobox("getValue"),
    };
    var params0 = $.param(params);
    document.location.href = "../custOrderController/filterPPTCustOrders?" + params0;
}

function checkAccessCustOrder(){
    $.ajax({
        type: "get",
        url: "../custOrderController/checkAccessCustOrder",
        dataType: 'json',
        success: function(data, textStatus) {
            if (!data.success && data.noAuth){
                window.location.href="../login/noauth.html"
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    }); 
}

function parseBoolean(val){
    if (val == undefined|| val == null) return false;
    var isInt = /^(-}+)?\d+$/.test(val);
    if (isInt&& val == "0") return false;
    else if (isInt&& val == "1") return true;
    else if (val.toLowerCase() == "false") return false;
    else if (val.toLowerCase() == "true") return true;
    else if (val.toLowerCase() == "f") return false;
    else if (val.toLowerCase() == "t") return true;
    else if (val.toLowerCase() == "n") return false;
    else if (val.toLowerCase() == "y") return true;
    else if (val.toLowerCase() == "no") return false;
    else if (val.toLowerCase() == "yes") return true;
    else return "";
}

function parseBooleanInt(val){
    var b = parseBoolean(val);
    if (b==undefined||b==null) return 0;
    else if (b==true) return 1;
    else return 0;
}

function isBlank(val){
    if (val == undefined|| val == null || val == "" || val== "0" || val == 0) return true;
    else return false;
}

function checkRadioBoxValue(control,field,fieldvalue){
    var checkboxs = $("#"+control).find("input[name='"+field+"']");
    for (var i=0;i<checkboxs.length;i++){
        if (checkboxs.get(i).value == ""+fieldvalue) checkboxs.get(i).checked=true;
    }
}

function toggleBtnShow(index){
    $('#button-bar a').css('display','none');
    $('#button-bar a:nth-child('+(index)+')').css('display','block');
}

function parseDateTime(s){
    if (!s) return new Date();
    var y = s.substring(0, 4);
    var m = s.substring(5, 7);
    var d = s.substring(8, 10);
    var h = s.substring(11, 13);
    var min = s.substring(14, 16);
    var sec = s.substring(17, 19);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d) && !isNaN(h) && !isNaN(min) && !isNaN(sec)) {
        return new Date(y, m - 1, d, h, min, sec);
    } else {
        return new Date();
    }
}

function formatDateTime(date){
    if (!date) return "";
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    var h = date.getHours();
    var min = date.getMinutes();
    var s = date.getSeconds();
    var str = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d) + ' ' + (h < 10 ? ('0' + h) : h)
        + ':' + (min < 10 ? ('0' + min) : min) + ':' + (s < 10 ? ('0' + s) : s);
    return str;
}

function parseDate(s){
    if (!s) return new Date();
    var y = s.substring(0, 4);
    var m = s.substring(5, 7);
    var d = s.substring(8, 10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
        return new Date(y, m - 1, d);
    } else {
        return new Date();
    }
}

function formatDate(date){
    if (!date) return "";
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    var str = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
    return str;
}

function translateUser(value){
    if (isBlank(value)) return "";
    var retVal = value;
    $.ajax({
        type:"post",
        url: "../userController/findUserById",
        data: {
            id:value
        },
        dataType: 'json',
        async:false,
        success: function(data, textStatus) {
            debugger;
            if ( data.data !=null && data.data.userName!=null){
                retVal = data.data.userName;
            }else{
                retVal = "";
            }
        },
        complete : function(XMLHttpRequest, textStatus) {
        },
        error : function(XMLHttpRequest,textStatus,errorThrown) {
            alert("Error:"+textStatus);
            alert(errorThrown.toString());
        }
    });
    return retVal;
}

</script>
</html>
